package com.kmzx.one.project.controller;

import com.kmzx.one.common.utils.MyAssert;
import com.kmzx.one.project.net.BaseResult;
import com.kmzx.one.project.others.dto.MateCateOutInfo;
import com.kmzx.one.project.others.dto.MaterialDetailInfo;
import com.kmzx.one.project.others.dto.PagedMateOutInfo;
import com.kmzx.one.project.others.dto.UserMateOutInfo;
import com.kmzx.one.project.service.MaterialService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * material  -> mate
 * category  -> cate
 */
@Api(tags = "快美甄选_[ 素材_接口 ]")
@RestController
public class MaterialController extends BaseController {

    @Autowired
    MaterialService materialService;


    @ApiOperation(value = "1.素材分类", notes = "素材分类",position = -1)
    @GetMapping(value = "mate/cate")
    public BaseResult findAllMaterialCategory(String userId) {
        try {
            List<MateCateOutInfo> outInfos = materialService.findAllMaterialCategory(userId);
            BaseResult success = BaseResult.Builder.SUCC().initSuccData(outInfos);
            return success;
        } catch (Exception e) {
            return handleException(e);
        }
    }


    @ApiOperation(value = "2.素材分类_下的素材", notes = "素材分类_下的素材",position = -1)
    @GetMapping(value = "mate/cateInfo")
    public BaseResult findAllMaterialById(String cateId, Integer pageNum, Integer pageSize, String userId) {
        try {
            PagedMateOutInfo outInfos = materialService.findAllMaterialById(cateId, pageNum, pageSize, userId);
            BaseResult success = BaseResult.Builder.SUCC().initSuccData(outInfos);
            return success;
        } catch (Exception e) {
            return handleException(e);
        }
    }

    @ApiOperation(value = "3.素材的详细信息", notes = "素材的详细信息")
    @GetMapping(value = "mate/cateDetail")
    public BaseResult findAllMaterialDetail(String mateId, String userId) {
        try {
            MaterialDetailInfo outInfos = materialService.findAllMaterialDetail(mateId,  userId);
            BaseResult success = BaseResult.Builder.SUCC().initSuccData(outInfos);
            return success;
        } catch (Exception e) {
            return handleException(e);
        }
    }


    @ApiOperation(value = "4.用户收藏的素材", notes = "用户收藏的素材")
    @GetMapping(value = "mate/user")
    public BaseResult findUserMaterialStore(String userId,Integer pageNum,Integer pageSize) {
        try {
            MyAssert.notNullObject(userId, "userId 为空");
            UserMateOutInfo info =  materialService.findUserMaterialStore(userId,pageNum,pageSize);
            BaseResult success = BaseResult.Builder.SUCC().initSuccData(info);
            return success;
        } catch (Exception e) {
            return handleException(e);
        }
    }



    @ApiOperation(value = "5.收藏/取消收藏 素材", notes = "收藏/取消收藏 素材")
    @GetMapping(value = "mate/user/store")
    public BaseResult doUserMaterialStore(String mateId,String userId) {
        try {
            MyAssert.notNullObject(mateId, "mateId 为空");
            MyAssert.notNullObject(userId, "userId 为空");
            materialService.doUserMaterialStore(mateId,userId);
            BaseResult success = BaseResult.Builder.SUCC().initSuccData(null);
            return success;
        } catch (Exception e) {
            return handleException(e);
        }

    }

    @ApiOperation(value = "6.增加素材下载次数", notes = "收藏/取消收藏 素材")
    @GetMapping(value = "mate/download")
    public BaseResult downloadMaterial(String mateId,String userId) {
        try {
            MyAssert.notNullObject(mateId, "mateId 为空");
            MyAssert.notNullObject(userId, "userId 为空");
            materialService.downloadMaterial(mateId,userId);
            BaseResult success = BaseResult.Builder.SUCC().initSuccData(null);
            return success;
        } catch (Exception e) {
            return handleException(e);
        }
    }







}
